<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/8/16
 * Time: 14:25
 */

namespace app\api\model;


class ProductProperty extends BaseModel
{
    protected $hidden = ['delete_time','update_time','create_time'];
    protected $autoWriteTimestamp = true;
    /**
     * 获取某个分类下的商品规格
     * @param $category
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getPropertyByCategory($category){
        $result = self::where('category_id','=',$category)->select();
        return $result;
    }

    /**
     * 创建商品规格
     * @param $info
     * @param $category_id
     * @return array|false
     */
    public  function createProperty($info,$category_id){
        $data = '';
        foreach ($info as $k=>$v){
            $data[$k]['name'] = $v;
            $data[$k]['category_id'] = $category_id;
        }
        return (new ProductProperty)->saveAll($data);
    }
    /**
     * 删除商品规格
     * @param $info
     * @return int
     */
    public static function deleteProperty($info){
        foreach ($info as $value ){
            $data[] = $value['id'];
        }
        return self::destroy($data);
    }
}